<?php
class ComplementariasController extends AppController {

	var $name = 'Complementarias';
	var $helpers = array('Access');
	
	function sesion_activa(){
		$usuario_activo=$this->Access->getMy('username');
		//Verificacion de sesion del sistema
		if(!$usuario_activo){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'users','action' => 'login'));
		}
	}
	
	function index() {
		$this->sesion_activa();
		$this->Complementaria->recursive = 0;
		$this->set('complementarias', $this->paginate());
	}

	function view($id = null) {
		$this->sesion_activa();
		if (!$id) {
			$this->Session->setFlash(__('Invalid complementaria', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('complementaria', $this->Complementaria->read(null, $id));
	}

	function add() {
	   $this->sesion_activa();	
		if (!empty($this->data)) {
			$this->Complementaria->create();
			if ($this->Complementaria->save($this->data)) {
				$this->Session->setFlash(__('La actividad complementaria ha sido guardada', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The complementaria could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
	   $this->sesion_activa();
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid complementaria', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Complementaria->save($this->data)) {
				$this->Session->setFlash(__('The complementaria has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The complementaria could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Complementaria->read(null, $id);
		}
	}

	function delete($id = null) {
	   $this->sesion_activa();
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for complementaria', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Complementaria->delete($id)) {
			$this->Session->setFlash(__('Complementaria deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Complementaria was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
